package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.Util.UserUtil;
import com.lnking.lnkingplace.model.enums.UserType;
import com.lnking.lnkingplace.model.request.isolation.place.PlaceAddRequest;
import com.lnking.lnkingplace.model.request.isolation.place.PlaceSearchRequest;
import com.lnking.lnkingplace.model.request.isolation.place.PlaceUpdateRequest;
import com.lnking.lnkingplace.service.IIsolationPlaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-08-27
 */
@RestController
@RequestMapping("/isolation-place")
@Api(tags = "隔离场所")
public class IsolationPlaceController {

    @Resource
    IIsolationPlaceService isolationPlaceService;
    @Resource
    UserUtil userUtil;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public ReturnResult getList(PlaceSearchRequest params) {
        if(userUtil.getUser().getType().equals(UserType.PLACE)){
            params.setPlaceName(userUtil.getUser().getName());
        }
        return ReturnResult.success(isolationPlaceService.pageList(params));
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public ReturnResult add(@Valid @RequestBody PlaceAddRequest params) throws Exception{
        isolationPlaceService.add(params);
        return ReturnResult.success();
    }

    @PostMapping("update")
    @ApiOperation("修改")
    public ReturnResult update(@Valid @RequestBody PlaceUpdateRequest params) throws Exception{
        isolationPlaceService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        isolationPlaceService.removeById(id);
        return ReturnResult.success();
    }

    @ApiOperation("查询详情")
    @GetMapping("get-details")
    public ReturnResult getDetails(String id){
        return ReturnResult.success(isolationPlaceService.getById(id));
    }
}
